package com.company;

import java.io.*;

public class HttpUtils {
    public static String getAjaxCotnent(String url) throws IOException {
        // PhantomJS 可执行文件路径
        String exePath = "D:/JavaDev/Software/Install/phantomjs-1.9.2-windows/phantomjs.exe";
        // javascript 文件路径
        String javascriptPath = "/js/codes.js";

        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec(exePath + " " + javascriptPath +" "+url);//这里我的codes.js是保存在c盘下面的phantomjs目录

        InputStream is = p.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuffer sbf = new StringBuffer();
        String tmp = "";
        while((tmp = br.readLine())!=null){
            sbf.append(tmp);
        }
        System.out.println(sbf.toString());
        return sbf.toString();
    }
}
